/**
 * 
 */
package com.cqan.mail.entity;

import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @Description 邮件实体类
 * @author slaton
 * @date 2012-5-16上午10:08:47
 *
 */
@SuppressWarnings("serial")
public class MailEntity implements Serializable{

	//收件人
	private List<User> to;
	
	//抄送人
	private List<User> cc;
	
	//密送
	private List<User> bcc;
	
	//主题
	private String subject;
	
	//邮件实体
	private String message;
	
	private List<File> attachments;

	
	
	public List<User> getTo() {
		return to;
	}

	public List<User> getCc() {
		return cc;
	}
	
	//设置收件人
	public void setCc(List<User> cc) {
		this.cc = cc;
	}
	
	//设置收件人
	public void setTo(String email,String name){
		if (to==null) {
			to = new ArrayList<User>();
		}
		User user = new User(email,name);
		to.add(user);
	}
	//设置收件人
	public void setTo(String email){
		if (to==null) {
			to = new ArrayList<User>();
		}
		User user = new User(email,email.substring(0, email.indexOf("@")));
		to.add(user);
	}
	
	//添加收件人
	public void addTo(String email) {
		if (to==null) {
			to = new ArrayList<User>();
		}
		User user = new User(email,email.substring(0, email.indexOf("@")));
		to.add(user);
	}
	
	//添加收件人
	public void addTo(String email,String name) {
		if (to==null) {
			to = new ArrayList<User>();
		}
		User user = new User(email,name);
		to.add(user);
	}
	
	//添加抄送件人
	public void addCc(String email) {
		if (cc==null) {
			cc = new ArrayList<User>();
		}
		User user = new User(email,email.substring(0, email.indexOf("@")));
		cc.add(user);
	}
	
	//添加抄送件人
	public void addCc(String email,String name) {
		if (cc==null) {
			cc = new ArrayList<User>();
		}
		User user = new User(email,name);
		cc.add(user);
	}
	
	
	public List<User> getBcc() {
		return bcc;
	}

	public void setBcc(List<User> bcc) {
		this.bcc = bcc;
	}
	
	//添加密送件人
	public void addBcc(String email) {
		if (bcc==null) {
			bcc = new ArrayList<User>();
		}
		User user = new User(email,email.substring(0, email.indexOf("@")));
		bcc.add(user);
	}
	
	//添加密送件人
	public void addBcc(String email,String name) {
		if (bcc==null) {
			bcc = new ArrayList<User>();
		}
		User user = new User(email,name);
		bcc.add(user);
	}


	public String getSubject() {
		return subject==null?"无主题":subject;
	}

	public void setSubject(String subject) {
		this.subject = subject;
	}

	public String getMessage() {
		return message==null?"无内容":message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public List<File> getAttachments() {
		return attachments;
	}

	public void setAttachments(List<File> attachments) {
		this.attachments = attachments;
	}
	
	public void addAttachments(File file) {
		if (attachments==null) {
			attachments = new ArrayList<File>();
		}
		attachments.add(file);
	}
	
	public class User{
		
		private String email;
		private String name;
		
		public User(){}
		
		public User(String email){
			this.email = email;
		}
		public User(String email,String name){
			this.email = email;
			this.name = name;
		}

		public String getEmail() {
			return email;
		}

		public String getName() {
			return name;
		}
		
	}
	
}
